var oscarObject = { 
	basicURL: location.hostname,	
    paramsMap: {}, 
    
    init: function () {    	
    	oscarObject.bindClick("calendar", "calendarId");
    	oscarObject.bindClick("award", "awardId");
    	oscarObject.bindClick("category", "categoryId");
    	oscarObject.bindClick("country", "countryId");
    	oscarObject.bindClick("person", "personId"); 
    	
    	$("div#nominations a[class='fulllist']").toggle(function(){
    		oscarObject.paramsMap["type"]= this.id;
    		oscarObject.getMovieList("#ulList");    		
    		this.title="显示全部电影";
    		$("#movieType").attr("src", "./img/img_winnerMarker_whole.png");
		},
		function() {			
			oscarObject.paramsMap["type"]= 0; 
			oscarObject.getMovieList("#ulList");			
			this.title="只看获奖影片";
			$("#movieType").attr("src","img/img_winnerMarker_whole_all.png");
		});    	    	
    },
    
    //binding-click method for the common click on the left side of the main page.
    bindClick: function(div, key) {
    	$("li#"+div+" a[class^='category-jumper invisibleWrapping']").bind('click', function (event) {    		    		    	   
    		oscarObject.paramsMap[key]= this.id;
    		$("li#"+div+" span").removeClass("hl").addClass("invisibleWrapping");
    	    $("li#"+div+" a").removeClass("hl").addClass("invisibleWrapping");    	    
    	    $(this).addClass("hl");
    	    oscarObject.getMovieList("#ulList");
    	});    	    	  	    
    },
              
    getMovieList: function (place) {    	
    	
    	var params = {"calendarId" : oscarObject.paramsMap["calendarId"], 
    			      "awardId" : oscarObject.paramsMap["awardId"],
    			      "categoryId" : oscarObject.paramsMap["categoryId"],
    			      "countryId" : oscarObject.paramsMap["countryId"],
    			      "personId" : oscarObject.paramsMap["personId"],
    			      "paging.currentPage" : oscarObject.paramsMap["curPage"],
    			      "type": oscarObject.paramsMap["type"]
    	}; 
    	
        var option = { data: params, url: 'getMovieListAction.action',
            success: function (ret) {            	
            	resp = ret;            	
            	movieListPanel.buildMovieListPanel(resp.movies, place);
            	pagination.initPage(resp.paging);
            },
            beforeSend :function(){
            	$("#movieListLoading").show();
            },
            complete:function(){                	
            	$("#movieListLoading").hide();
            }            
        };
       
        $.ajax(option);
    } ,
    
    getMovieListById: function(movieId, roleId, place) {    	    	
    	var option = { data: {"movieId": movieId, "roleId":roleId}, url: 'getRelevantMovie!getRelevantMovie.action',
                success: function (ret) {            	
                	resp = ret;            	
                	movieListPanel.buildMovieListPanel(resp.relevantMovies, place);                	
                }                        
            };
    	
        $.ajax(option);
    },
    
    getMovieListByPersonId: function(personId, place) {    	    	
    	var option = { data: {"personId": personId}, url: 'getRelevantMovie!getRelevantMovieByPerson.action',
                success: function (ret) {            	
                	resp = ret;            	
                	movieListPanel.buildMovieListPanel(resp.relevantMovies, place);                	
                }                        
            };
    	
        $.ajax(option);
    }
};


var movieListPanel = {
	    movieTabHTML:null,
		
	    buildMovieListPanel: function(list, place) {
	    	movieListPanel.clearContent(place);		    		
	    	movieListPanel.initMovieList(list, place);	
	    	toolTips.initTipWithAnimation();	    	
	    	$(".tabs").tabs(); 
	    	movieTab.init();	    	
	    },	    	    
	 	    	    	
	    initMovieList: function (list, place) {  
	    	var ul = $(place);
	    	for(i = 0; i < list.length; i++) {
	    		movieListPanel.addMovieList(ul, list[i]);	    		
	    	} 	    		    	
	    },
	    
	    addMovieList: function (panel, movie) { 	    	
	    	var li = $("<li/>").addClass("Nominee clearfix");       	
	    	var containerDiv=$("<div/>").addClass("nomineeListItemContainer"); 	    	
	    	containerDiv.append(movieListPanel.createPickDiv(movie));
	    	containerDiv.append(movieListPanel.createRatingDiv(movie));
	    	containerDiv.append(movieListPanel.createImageDiv(movie));	    	
	    	containerDiv.append(movieListPanel.createBasicInfoDiv(movie));	    		    	  	    
	    	li.append(containerDiv);
	    	li.append(movieListPanel.movieTabHTML);	    	
	    	panel.append(li);
	    	if (movie.statistics != null) {
	    		rating.initRating("rating_star_"+movie.id, movie.statistics.scoreDisplay, movie.id, true,rating.sendMovieScore);
	    	}
	    },
	    
	    createRatingDiv: function(movie) {
	      	var ratingDiv = $("<div id='ratingDiv'/>");
	      	var movieRating = "rating_star_" + movie.id;
	      	var input = $("<div id='"+movieRating+"'/>");	      	
	      	ratingDiv.append(input);
	      	return ratingDiv;
	    },
	    
	    createPickDiv: function(movie) {	    		    	   	
		   var pick = $("<div class='nomineeGamePicks'/>");
		   var click = $("<div class='makePick' id=" +movie.id+"/>");
		   var href = $("<a class='image myPickDisabled incorrect' id='playAlong_413'/>");
		   $.each(movie.mpacs, function(index, value) {	    		    			    			
   			if (value.type == 2 && (value.award.id == oscarObject.paramsMap["awardId"] || oscarObject.paramsMap["awardId"] == null || oscarObject.paramsMap["awardId"] ==0)) {
   				href.attr('awardType','award');
   				href.css({background:'url(./img/img_winnerMarker_whole.png) no-repeat scroll 27px 4px transparent',cursor:'pointer'});
   			}
   	    });	 
		   var shardButton = $("<div class='sharePick' style='display:inline;'><a>Sina Weibo</a></div>");
		   click.append(href);
		   pick.append(click);
		   pick.append(shardButton);
		   
		   return pick;
	    },
	     
	    createBasicInfoDiv: function(movie) {	    	
	    	var basicInfo = $("<div class='nomineeTitle'/>");
	    	var title = $("<div style='width:310px;overflow:hidden;white-space:nowrap;display: inline-block;'/>")
	    	.append($("<h4 style='padding-top:5px;'/>").append($("<a target='_blank' href='movie!load?movie.id=" +movie.id+"' title='"+movie.nameCn + " "+movie.name+"'>"
	    			+movie.nameCn+" <font style='font-size:12px;'>"+ movie.name+"</font></a>")));	        
	        var nomineeDetail = $("<div class='nomineeNominated detailedInfo'/>");	        
	        nomineeDetail.append(movieListPanel.createDirectorDiv(movie));
	        nomineeDetail.append(movieListPanel.createActorDiv(movie));
	        nomineeDetail.append(movieListPanel.createCategoryDiv(movie));
	        basicInfo.append(title);
	        basicInfo.append(nomineeDetail);
	        
			return basicInfo;
	    },
	    
	    createDirectorDiv: function(movie) {	    	
	    	var director = $("<div id='director' >导演: </div>");
	    	$.each(movie.mprs, function(index, value) {
	    		if(value.role.id == 1) {
	    			var name = value.person.displayName;
	    			var id = value.person.id;
	    			director.append($("<span class='mcard'><a target='_blank' href='person!load?person.id=" + id + "' title='" + name + "'>" + name+ "</a>&nbsp;&nbsp;</span>"));	    			
	    		}
	    	});
	    										
			return director;	    	
	    },
	    
	    createActorDiv: function(movie) {	    	
	    	var actor = $("<div id='actor' >主演: </div>");	    	
	    	$.each(movie.mprs, function(index, value) {
	    		if(value.role.id >= 2 && value.role.id<=5) {
	    			var name = value.person.displayName;
	    			var id = value.person.id;
	    			actor.append($("<span class='mcard'><a target='_blank' href='person!load?person.id=" + id + "' title='" + name + "'>" + name+ "</a>&nbsp;&nbsp;</span>"));	    			
	    		}
	    	});
	    	
			return actor;	
	    },
	    
	    createCategoryDiv: function(movie) {	    	
	    	var category = $("<div id='category' >分类: </div>");	    	
	    	$.each(movie.categories, function(index, value) {	    		
	    			var name = value.displayName;	    			
	    			category.append($("<span class='mcard'>" + name+ " </span>"));	    				    		
	    	});
	    	
			return category;	
	    },
	    	    	    	    
	    createImageDiv: function(movie){		    	
		    var imageDiv = $("<div/>").addClass("nomineeImage");
		    var href = $("<a target='_blank' href='movie!load?movie.id=" + movie.id + "'/>");
	    	var data = "uploaded/images/thumb.png";
	    	if (movie.image != null) {
	    		data = movie.image.src; 
	    	}
	    	var img = $("<img class='tip_trigger' src='"+ data +"' width='70' height='88'/>");
	    	var tip = $("<span class='tip'><img class='tipImg' src='"+ data +"'/></span>;")
	    	href.append(img);
	    	href.append(tip);
	    	imageDiv.append(href);
	    	
	    	return imageDiv;	    	
	    },
	    
	  //obsoleted method
	    createAwardDiv: function(movie) {
	    	var award = $("<div id='award' class='mcard'>"+movie.calendar.displayName+":<br/></div>");	    	
	    	$.each(movie.mpacs, function(index, value) {	    		
	    			var awardName = value.award.displayName;
	    			if ( value.person != null) {
	    				var id = value.person.id;
		    			var name = value.person.displayName;		    			
		    			award.append($("<div style='display:inline;'>" + awardName + "</div> <a href='person!load?person.id=" + id + "'>" + name+ " </a><br/>"));
	    			} else {
	    				award.append($("<div>" + awardName + "</div>"));
	    			}
	    			
	    			alert(value.type);
	    	});	    					    		    				
									
			return award;	
	    },
	    
	    clearContent: function(place) {		    	
	    	if(movieListPanel.movieTabHTML == null)
	    	    movieListPanel.movieTabHTML = $("#storedMovieTab").html();
	    	$(place + " li").remove();	    	
	    }
};

//movieTab effects
var movieTab = {
	identity:null,
	
	init: function() {
		$('#dropDownMovie').hide();	
		$(".makePick").unbind("click");
		$(".makePick").toggle(function(){			
			movieTab.identity = $(this);
			movieTab.getMovie(this);
			dropDownMovieDIV = $(this).parent().parent().parent().find('#dropDownMovie');			
			dropDownMovieDIV.css({margin:'5px 5px 0px 5px'}).addClass("dropDownMovie");
			dropDownMovieDIV.show("blind",{}, 1000);
			loading = dropDownMovieDIV.find('#movieTabLoading');
			loading.show();
		},
		function() {			
			dropDownMovieDIV = $(this).parent().parent().parent().find('#dropDownMovie');
			dropDownMovieDIV.removeClass("dropDownMovie");
			dropDownMovieDIV.hide("blind",{}, 250);			
		});				
	},		
	
	getMovie: function(handler) {
    	var option = { data: {"movieId": handler.id},  url: 'getMovieAction.action',
                success: function (ret) {            	
                	resp = ret;            	
                	movieTab.buildMovieTab(resp.movie);                	
                } ,                
                complete:function(){                	
                	$(handler).parent().parent().parent().find('#dropDownMovie').find('#movieTabLoading').hide();
                }
            };

         $.ajax(option);
    },
	
	buildMovieTab: function(movie) {
		movieTab.createBasicInfoTab(movie);		
		movieTab.createPlotTab(movie);
		movieTab.createPicTab(movie);
		toolTips.initTipWithoutAnimation();
	},
	
	createBasicInfoTab: function(movie){
		var tab1 = movieTab.identity.parent().parent().parent().find('#tab1');
		if (movie.image != null) {
			img = tab1.find('div>img:first');
			img.attr("src", movie.image.src);			
    	}
							
		tab1.find('#datetime').text(movie.datetime.substr(0,10));
		
		var countries = "";
		$.each(movie.countries, function(index, value) {
    		countries += (value.displayName + " ");
    	});
		tab1.find('#country').text(countries);
		
		var languages = "";
		$.each(movie.languages, function(index, value) {	    		
			languages += (value.displayName + " ");
    	});
		tab1.find('#language').text(languages);
		
		var categories = "";
		$.each(movie.categories, function(index, value) {	    		
			categories += (value.displayName + " ");
    	});
		tab1.find('#category').text(categories);
				
		tab1.find('#director *').remove();
		$.each(movie.mprs, function(index, value) {
    		if(value.role.id == 1) {
    			var name = value.person.displayName;
    			var image = value.person.image;
    			var id = value.person.id;
    			var director = tab1.find('#director');
    			var trigger = $("<span class='tip_person_trigger mcard' style='max-width:240px; height:15px;display:inline-block;'><a target='_blank' href='person!load?person.id=" + id +  "'>" + name+ "</a>&nbsp;&nbsp;&nbsp;</span>");
    			trigger.append(toolTips.popupImg(image));
    			director.append(trigger);
    		}
    	}); 
		
		tab1.find('#actor *').remove();
		$.each(movie.mprs, function(index, value) {
    		if(value.role.id >= 2 && value.role.id<=5) {
    			var name = value.person.displayName;
    			var id = value.person.id;
    			var image = value.person.image;
    			var actor = tab1.find('#actor');
    			var trigger = $("<span class='tip_person_trigger mcard' style='max-width:240px; height:15px;display:inline-block;'><a target='_blank' href='person!load?person.id=" + id +  "'>" + name+ "</a>&nbsp;&nbsp;&nbsp;</span>");
    			trigger.append(toolTips.popupImg(image));
    			actor.append(trigger);
    		}
    	});
				
		tab1.find('#award *').remove();
		tab1.find('#award').append(movie.calendar.displayName+":");
		$.each(movie.sortedMpacs, function(index, value) {
			var awardName = value.award.displayName;
			if ( value.person != null) {
				var id = value.person.id;
				var image = value.person.image;
    			var name = value.person.displayName;
    			var award = tab1.find('#award');
    			var html = value.type == 1 ? "<font style='font-size:12px;color:#B1B1B1;'>(" +value.typeName +")</font>" : "<div id='winner'/>"
    			var li = $("<li>" + awardName + "</li>");
    			li.append(html);
    			var trigger = $( "<span class='tip_person_trigger mcard' style='margin-left:5px;max-width:300px;height:15px;display:inline-block;'><a target='_blank' href='person!load?person.id=" + id + "'> " + name+ "</a></span>");
    			trigger.append(toolTips.popupImg(image));
    			li.append(trigger);
    			award.append(li);
			} else {
				var html = value.type == 1 ? "(" +value.typeName +")" : "<div id='winner'/>" 				
				tab1.find('#award').append($("<li>" + awardName + "</li>").append(html));
			}						
		});
		
		var text = "分享：" + movie.calendar.displayName + "奥斯卡获奖电影#" + movie.displayName +"# -- 奥斯卡中文网";
		var pic = movie.image.src;
		var url = "http://www.oscarchinese.com/movie!load?movie.id=" + movie.id;
		var data = "{'text':'"+text+"','pic':'"+pic+"','url':'"+url+"'}";		
		movieTab.identity.parent().parent().parent().find('ul').find('#bdshare').attr("data",data);
						
	},
	
	createPlotTab: function(movie) {
		var tab2 = movieTab.identity.parent().parent().parent().find('#tab2');
		tab2.find("#plot").html(movie.plot);
		tab2.find("#comment").html(movie.plot);
	},
	
	createPicTab: function(movie){
		var tab3 = movieTab.identity.parent().parent().parent().find('#tab3');
		var pictures = tab3.find('#pictures');
		tab3.find('#pictures>img').remove();	
		
		//TODO: dynamically load the movie pics from the db
		$.each(movie.images, function(index, value) {    		
    		var url = value.src; 
    		var img = $("<img/>");
    		img.attr("src", url).addClass("mainTabPics");    		
    		pictures.append(img);    			    		
    	}); 
		pictures.hover(
			function () {					
				footbar = $(this).find('#footbar');
				footbar.css("display","inline");					
			},
			function () {	
				footbar.hide("slide",{}, 400);
			}
		);
		
		picTab.initPics(tab3);
		pictures.find('#footbar>img').unbind('click');
		tab3.find('#pictures #swipe_nav_prev').bind('click',function() {  			
	      return picTab.swapFirstLast($(this).parent().parent().parent(), true); //swap first image to last position
       });
	  
		tab3.find('#pictures #swipe_nav_next').bind('click',function() {					
	      return picTab.swapFirstLast($(this).parent().parent().parent(), false); //swap last image to first position
      });
	}		
};

//Pagination

var pagination = {
		
		initPage: function(page){	    	
	    	$('#totalCount').text(page.totalCount);
	    	$('#pageIndicator').text(page.currentPage+'/'+page.totalPage);
	    	$('#preArrow').addClass("right").unbind('click');
	    	$('#nextArrow').addClass("right").unbind('click');
	    	
	    	if( page.currentPage < page.totalPage ) {
	    		pagination.initArrow(page.currentPage, $('#nextArrow'), "+"); 		
	    	} else {
	    		$('#nextArrow').css({"color": "#D2E6FA","cursor":"default"});
	    	}
	    	$('#nextArrow').text(">>");
	    	
	    	if( page.currentPage>1 ) {
	    		pagination.initArrow(page.currentPage, $('#preArrow'), "-"); 	    		
	    	} else {
	    		$('#preArrow').css({"color": "#D2E6FA","cursor":"default"});
	    	}
	    	$('#preArrow').text("<<");
	    },
	    
	    initArrow: function (currentPage, arrow, direction) {	    	
	    	arrow.css({"color": "#F3F3E9","cursor":"pointer"});	    	
	    	arrow.bind('click', function(event) {	    		
	    		if (direction == "+") {
	    			oscarObject.paramsMap["curPage"] = currentPage + 1;	
	    		} else {
	    			oscarObject.paramsMap["curPage"] = currentPage - 1;
	    		}        			    	        		
        		oscarObject.getMovieList("#ulList");
        		oscarObject.paramsMap["curPage"] = 1;
        	});  	   
	    }	
};

//Tooltips
var toolTips = {
		//expand the details
		initTipWithAnimation: function() {						 
		  $(".tip_trigger").hover(
			function () {					
				 tip = $(this).parent().find('.tip');								
				 tip.css({  top: -200, left: this.offsetWidth + 15 , position:"relative", display:"inline-block"});
				 tip.show("slide",{}, 400);				 
			},
			  function () {						
			     //tip.hide("explode",{}, 100);				
			    tip.hide();
			  }
			);
		},
		
		//tip on the person 
		initTipWithoutAnimation: function() {						 
			  $(".tip_person_trigger").hover(
				function () {					
					 tip = $(this).find('.tip');					 
					 tip.css({  top: this.offsetTop - 210, left: this.offsetLeft + this.offsetWidth/2 , display:"inline-block"});					 
					 tip.show();
				},
				  function () {										     
					tip.hide();
				  }
				);
			},
			
		initPersonTipWithLazyLoad: function(){
			var img = $("<img class='tipImg' src='uploaded/images/thumb.png'/>");
			$(".tip_person_trigger").hover(
				function () {					
					 tip = $(this).find('.tip');					 
					 tip.css({  top: this.offsetTop - 210, left: this.offsetLeft + this.offsetWidth/2 , display:"inline-block"});
					 //<div id='movieListLoading' class='personLoadingImg'/>
					 var option = { data: {"personId": tip.attr("id")}, url: 'toolTip!getPersonTip.action',
			                success: function (ret) {
			                	resp = ret; 
			                	img.attr("src", resp.person.image.src);
			                	tip.append(img);	
			                }, 
			                beforeSend :function(){			                	
			                	$("#personLoadingImg").show();			                	
			                },
				            complete:function(){                	
				            	$("#personLoadingImg").hide();
				            }    
						};				          
					 $.ajax(option);					 				
					 tip.show();
				},
				  function () {						
					tip.hide();
				  }
				);
		},
		
		hoverCard: function(tag, uid, type){			
			if(uid == null){						
				$("a").each(function(){					
					if(typeof($(this).attr("uid"))!="undefined"){
						//var identity = $("'" + tag+ "[uid=" +uid +"]'")						
						$(this).append($("<span class='tip'><div class='personLoadingImg'/></span>"));
						var img = $("<img class='tipImg'/>");
						$(this).hover(
							function () {					
								 tip = $(this).find('.tip');	
								 uid = $(this).attr("uid");
								 tip.css({  top: this.offsetTop - 210, left: this.offsetLeft + this.offsetWidth/2 , display:"inline-block"});								 								
								 var option = { data: {"personId": uid}, url: 'toolTip!getPersonTip.action',
						                success: function (ret) {
						                	resp = ret; 
						                	img.attr("src", resp.person.image.src);						                	
						                	tip.append(img);
						                }, 
						                beforeSend :function(){
						                	$(".tipImg").remove();
						                	$(".personLoadingImg").show();
						                },
							            complete:function(){
							            	$(".personLoadingImg").hide();
							            	//$(".tipImg").show();
							            }    
									};				          
								 $.ajax(option);								 
								 tip.show();
							},
							  function () {						
								tip.hide();
							  }
							);					  
					}
				})															
			}
			
		},
							
		popupImg: function(image){			
			var data = "uploaded/images/thumb.png";
	    	if (image != null) {
	    		data = image.src; 
	    	}
			var imgDiv = $("<span class='tip'><img class='tipImg' src='"+ data+"'/></span>");
			return imgDiv;
		}
};

var request = {
    QueryString : function(val)
    {
        var uri = window.location.search;        
        var re = new RegExp("" +val+ "=([^&?]*)", "ig");
        return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
    }
};

//Rating
var rating = {		
		
		initRating: function(place, value, id, readOnly, callBack) {
			$("#"+place).webwidget_rating_bar({
			sourceId: id,
			rating_star_length: '5',
			rating_default_value: value,
			rating_function_name: callBack,
			directory: './img',
			readOnly: readOnly
			});
		},
				
		sendMovieScore: function(id, score, readOnly){				
			var option = { data: {"movieId": id,"score":score}, url: 'updateStatistics!updateMovieScore.action',
	                success: function (ret) {            	
	                	resp = ret; 
	                	var movieRating = "rating_star_" + id;
	                	var input = $("<div id='"+movieRating+"'/>");	   
	                	$("#ratingDiv #"+movieRating).siblings().remove();
	                	rating.initRating("rating_star_"+id, resp.statistics.scoreDisplay, id, readOnly,rating.sendMovieScore );	                		                	
	                	$("div#statistics div#scored").text(resp.statistics.scored);	                	
	                	rating.msgBox("谢谢参与,您的评分系统已接受.");
	                }                	               
	            };

			 if (score!=null&&score!="") {
	           $.ajax(option);
			 } else {
				 alert("请勿频繁评分!")
			 }
		},
					
		sendPersonScore: function(id, score, readOnly){				
			var option = { data: {"personId": id,"score":score}, url: 'updateStatistics!updatePersonScore.action',
	                success: function (ret) {            	
	                	resp = ret; 
	                	var movieRating = "rating_star_" + id;
	                	var input = $("<div id='"+movieRating+"'/>");	   
	                	$("#ratingDiv #"+movieRating).siblings().remove();
	                	rating.initRating("rating_star_"+id, resp.statistics.scoreDisplay, id, readOnly, rating.sendPersonScore);	                		                	
	                	$("div#statistics div#scored").text(resp.statistics.scored);	                	
	                	rating.msgBox("谢谢参与,您的评分系统已接受.");
	                }                	               
	            };
				if (score!=null&&score!="") {
					$.ajax(option);
				} else {
					alert("请勿频繁评分!")
				}
		},
						
		clickBinding: function(id){
			$("div#statistics #watchedLink").bind('click', function (event) {    
				var option = { data: {"movieId": id}, url: 'updateStatistics!updateWatched.action',
		                success: function (ret) {
		                	resp = ret; 
		                	$("div#statistics div#watched").text(resp.statistics.watched);
		                	rating.msgBox("谢谢参与");
		                }                	               	            
				};
		          
				$.ajax(option);
			});
			
			$("div#statistics #wantedLink").bind('click', function (event) {    
				var option = { data: {"movieId": id}, url: 'updateStatistics!updateWanted.action',
		                success: function (ret) {
		                	resp = ret; 
		                	$("div#statistics div#wanted").text(resp.statistics.wanted);
		                	rating.msgBox("谢谢参与");
		                }                	               	            
				};
				  $.ajax(option);
			});
			
			$("div#statistics #favoriteLink").bind('click', function (event) {    
				var option = { data: {"personId": id}, url: 'updateStatistics!updateFavorite.action',
		                success: function (ret) {
		                	resp = ret; 
		                	$("div#statistics div#favorite").text(resp.statistics.favorite);
		                	rating.msgBox("谢谢参与");
		                }                	               	            
				};
				  $.ajax(option);
			});
		},
		
		msgBox: function(msg) {
			var msgDiv = $("<div class='msgBox'>"+msg+"</div>");
        	$("body").append(msgDiv);
        	msgDiv.show("blind",{}, 1500);                	
        	setTimeout(function() {msgDiv.animate({ opacity: 0, bottom:'-20px'}, 1500);}, 4500);
        	setTimeout(function() {msgDiv.remove();}, 5500);			
		}
	
};
 
//Curtain
var curtain = {
		
		curtainopen:false,
		
		init: function(){
		$(".rope").click(function(){
			$(this).blur();
			if (curtain.curtainopen == false){ 
				$(this).stop().animate({top: '0px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
				$(".leftcurtain").stop().animate({width:'60px'}, 2000 );
				$(".rightcurtain").stop().animate({width:'60px'},2000 );
				curtain.curtainopen = true;
			}else{
				$(this).stop().animate({top: '-40px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
				$(".leftcurtain").stop().animate({width:'50%'}, 2000 );
				$(".rightcurtain").stop().animate({width:'51%'}, 2000 );
				curtain.curtainopen = false;
			}
			return false;
		});
		}
		
};

